<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page session="false" import="com.hunqiu.user.cache.CacheService"
	import="org.springframework.web.context.*"
	import="org.springframework.web.context.support.*"
	import="org.codehaus.jackson.map.*" import="org.codehaus.jackson.*"
	import="com.hunqiu.user.vo.UserSessionVO"
	import="com.hunqiu.user.vo.UserVO" import="java.util.*"%>
<%
	response.setCharacterEncoding("GBK");
	WebApplicationContext springContext = WebApplicationContextUtils
			.getWebApplicationContext(this.getServletContext());

	final CacheService cacheService = (CacheService) springContext
			.getBean("cacheService");

	String _uid = request.getParameter("uid");

	if (null == _uid)
		return;
	long uid = Long.parseLong(_uid);

	String function = request.getParameter("t");
	if (null == function)
		return;

	boolean login = false;
	String _login = request.getParameter("login");
	if (null != _login)
		login = Boolean.valueOf(_login);

	Map<String, Object> result = new HashMap<String, Object>();
	//获取用户信息
	if (function.equals("user")) {
		UserVO user = cacheService.getUser(uid);
		if (null == user) {
			return;
		}
		result.put("uid", user.getUserId());
		result.put("name", user.getUserName());
	}

	//获取用户session信息
	else if (function.equals("session")) {
		UserSessionVO session = cacheService.getUserSession(uid);
		if (null == session) {
			return;
		}
		result.put("uid", session.getUserId());
		result.put("time", session.getLastTime());
		result.put("isLogin", session.isLogin());
	}

	//编辑登录信息
	else if (function.equals("session_edit")) {
		cacheService.editSession(uid, login);
	}

	JsonFactory jsonFactory = new MappingJsonFactory();
	ObjectMapper mapper = (ObjectMapper) jsonFactory.getCodec();
	mapper.writeValue(out, result);
%>